﻿function gotoPage(formName, pageNum1) {
    var pattern = /^([0-9])+$/;
    var flag = pattern.test(pageNum1);
    if (flag) {
        pageNum = pageNum1;
    } else {
        pageNum = 1;
    }
    var pageInputName = "currentPage";
    var pageInput = null;
    var form = document.getElementsByName(formName)[0];

    if (document.getElementsByName(pageInputName).length != 0) {
        pageInput = document.getElementsByName(pageInputName)[0];
        pageInput.value = pageNum;
    } else {
        pageInput = document.createElement("input");
        pageInput.type = "hidden";
        pageInput.name = "currentPage";
        pageInput.value = pageNum;

        form.appendChild(pageInput);
    }
    form.submit();
}